﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PexMe.Core;
using Microsoft.ExtendedReflection.Metadata;

namespace PexMeHelper
{
    public class ClassAnalyzer
    {
        /// <summary>
        /// Analyzes a class and prints all its fields and methods
        /// </summary>
        public static void AnalyzeClass(string assemblyname, string typename)
        {
            TypeEx type;
            if (!MethodOrFieldAnalyzer.TryGetTypeExFromName(assemblyname, typename, out type))
            {
                Console.WriteLine("Failed to retrieve type with name: " + typename);
                return;
            }

            TypeDefinition tdef = type.Definition;

            Console.WriteLine("All fields");
            foreach(FieldDefinition f in tdef.DeclaredInstanceFields)
            {
                Console.WriteLine("Field: " + f.FullName);
            }

            foreach (MethodDefinition m in tdef.DeclaredInstanceMethods)
            {
                Console.WriteLine("Method: " + MethodOrFieldAnalyzer.GetMethodSignature(m));
            }
        }
    }
}
